x = {8: {'children': [{'id': 3, 'authName': '角色列表', 'url': '/roles/', 'level': '1', 'pid': 8}, {'id': 6, 'authName': '权限列表', 'url': '/rights/', 'level': '1', 'pid': 8}]}, 7: {'children': [{'id': 4, 'authName': '用户列表', 'url': '/users/', 'level': '1', 'pid': 7}]}, 4: {'children': [{'id': 5, 'authName': '添加客户', 'url': '/users/add/', 'level': '2', 'pid': 4}, {'id': 9, 'authName': '修改客户', 'url': '/users/edit/', 'level': '2', 'pid': 4}]}, 3: {'children': [{'id': 10, 'authName': '添加角色', 'url': '/roles/add/', 'level': '2', 'pid': 3}, {'id': 11, 'authName': '修改角色', 'url': '/roles/edit/', 'level': '2', 'pid': 3}]}}
# import copy
third_dict = {}
third_id_list = []
for k,v in x.items():
    # print(k,v)
	# third_dict[k] = v
	print(k,v['children'][0]['id'])
	#{'id': 5, 'authName': '添加客户', 'url': '/users/add/', 'level': '2', 'pid': 4}
	t = v['children'][0]
	if t['id'] in x:
		print(k,v)
		third_id_list.append(t['id'])
		t['children'] = x[t['id']]['children']
	# print(111, t['id'], x[t['id']])
	# x.pop(t['id'])

print(third_id_list)
for item in third_id_list:
	del x[item]

print(x)
